/**
  @creator: cilang
  @qq: 1019383856
  @bili: https://space.bilibili.com/433915419
  @gitee: https://gitee.com/OpencvLZG
  @github: https://github.com/OpencvLZG
  @since: 2023/11/26
  @desc: //TODO
**/

package service

import (
	"errors"
	"ginFlutterBolg/internal/dao"
	"ginFlutterBolg/internal/model"
)

type (
	UserFriendService struct {
	}
)

func (u *UserFriendService) FriendUser(friend *model.UserFriend) error {
	userFriendDao := new(dao.UserFriendDao)
	hadFriend, err := userFriendDao.QueryHasFriend(friend)
	if err != nil {
		return err
	}
	if hadFriend {
		return errors.New("已存在该关系")
	}
	err = userFriendDao.FriendUser(friend)
	return err
}

func (u *UserFriendService) GetFriendListOffset(page int, userId int64) (*[]model.UserFriend, error) {
	userFriendDao := new(dao.UserFriendDao)
	friendList, err := userFriendDao.GetFriendLimitOffset(page, userId)
	return friendList, err
}
